package org.example.juc.aqs;
import java.util.concurrent.TimeUnit;

public class InterruptDemo implements Runnable {



    public void run() {

        //Thread.currentThread().isInterrupted() 默认false 不中断线程继续执行
        while (!Thread.currentThread().isInterrupted()) {
            try {
                TimeUnit.SECONDS.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
                Thread.currentThread().interrupt(); //再次调用中断、阻止线程继续执行下去
            }
        }
        System.out.println("Thread end!");
    }

    public static void main(String[] args) throws InterruptedException {
        Thread th1 = new Thread(new InterruptDemo());
        th1.start();
        Thread.sleep(1000);
        th1.interrupt(); //中断  我现在要中断
        //Thread.interrupted(); //线程复位
    }
}